package com.ruoyi.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ToolUtils {
    public static Long[] StringToLong(String[] str) {
        Long[] arr = new Long[str.length];
        for (int i = 0; i < str.length; i++) {
            arr[i] = Long.parseLong(str[i]);
        }
        return arr;
    }

    // 移除字符串数组中的某一项
    public static String RemoveTargetForString(String ids, Long target) {
        String[] idArray = ids.split(",");
        List<String> idList = new ArrayList<>();
        System.out.println("idArray:" + idArray);
        System.out.println("target:" + target);
        for (String id : idArray) {
            long value = Long.parseLong(id);
            if (value != target) {
                idList.add(id);
            }
        }
        System.out.println("idList:" + idList);
        return String.join(",", idList);
    }

    public static Long DateToTimestamp(String dateStr) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = simpleDateFormat.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (date != null) {
            return date.getTime();
        }
        return null;
    }
}
